package cn.king.springframework.beans.factory.support;

import cn.king.springframework.beans.BeanException;
import cn.king.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry{
 private Map<String,BeanDefinition> beanDefinitionMap = new HashMap<>();
 @Override
 protected BeanDefinition getBeanDefinition(String beanName) throws BeanException {
  BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
  if(null == beanDefinition){
   throw new BeanException("No bean named '" + beanName + "' is defined");
  }
  return beanDefinition;
 }

 @Override
 public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
  beanDefinitionMap.put(beanName,beanDefinition);
 }
}
